import { number } from 'vue-types';
import { defineStore } from 'pinia';
import { message } from 'ant-design-vue';
import {UserTypes} from "@/type"
interface ICommonState {
  loadingIdList: number[];
  user:Partial<UserTypes.IUserItem>,
  token:string;
  cartDataList:any[],
  userList:any[],
  storeList:any[]
}

// 创建store实例
export const CommonStore = defineStore({
  id: 'commonStore',
  state: (): ICommonState => {
    return {
      loadingIdList: [], // 当前请求的的id,长度大于0，则页面正在请求遮罩的状态
      user:{},
      token:"",
      cartDataList:[],
      userList:[],
      storeList:[]
    };
  },
  persist: {
    enabled: true,
    strategies: [{ storage: sessionStorage, paths: ['cartDataList', 'token', 'user','userList','storeList'] }],
  },
  getters: {
    globalLoading(state): boolean {
      return !!state.loadingIdList.length;
    },

   
  },
  actions: {
    
    loadingIdListPush(id:number) {
      this.$state.loadingIdList.push(id);
    },
    loadingIdListPop() {
      this.$state.loadingIdList.pop();
    },
 
  },
});
